﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewsDiscoveryEngine;
using NewsMine.DomainObjects;

namespace NewsDiscoveryEngine
{
    [Serializable]
    public class HtmlDownloadJob : BaseJob
    {
        public string Url { get; set; }

        public override bool ExecuteJob()
        {
            //todo: need to process the job and return the records.

            var result = DownloadHtmlContent(Url);

            ProcessOutput(result);

            return true;
        }

        public static HtmlContentFromUrl DownloadHtmlContent(string url)
        {

            HtmlContentFromUrl htmlContentFromUrl = NewsMine.Utilities.WebHelper.DownLoadHttpTextByCompressionEnabledWithExtraInfo(url);

            if (htmlContentFromUrl != null)
            {
                htmlContentFromUrl.DownloadedTimeStamp = DateTime.UtcNow;
            }


            return htmlContentFromUrl;
            //string htmlContent = NewsMine.Utilities.WebHelper.DownloadHtmlFromUrl(url);
            //return new HtmlContentFromUrl { Url = url, HtmlContent = htmlContent };
        }
    }
}
